package com.gxa.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Query;
import com.gxa.modules.sys.dto.ClockLeaveDto;
import com.gxa.modules.sys.dto.ClockRankDto;
import com.gxa.modules.sys.dto.SignInDto;
import com.gxa.modules.sys.entity.Clock;
import com.gxa.modules.sys.mapper.ClockMapper;
import com.gxa.modules.sys.service.ClockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ClockServiceImpl extends ServiceImpl<ClockMapper, Clock> implements ClockService {

    @Resource
    private ClockMapper clockMapper;

    @Override
    public List<Clock> queryByPageList(Map<String, Object> params) {


        List<Clock> clocks = this.clockMapper.queryByPageList(params);

        return clocks;
    }

    @Override
    public void updateSeatStateByUserId(Integer userId) {
        this.clockMapper.updateSeatStateByUserId(userId);
    }

    @Override
    public void updateMyOrderStateByUserId(Integer userId) {
        this.clockMapper.updateMyOrderStateByUserId(userId);
    }

    @Override
    public void updateSeatStateByOrderId(ClockLeaveDto params) {
        this.clockMapper.updateSeatStateByOrderId(params);
    }

    @Override
    public void updateMyOrderStateByOrderId(ClockLeaveDto params) {
        this.clockMapper.updateMyOrderStateByOrderId(params);
    }

    @Override
    public void updateOrderSeatStateByOrderId(ClockLeaveDto params) {
        this.clockMapper.updateOrderSeatStateByOrderId(params);
    }

    @Override
    public void updateClockEndTimeByEndTime(ClockLeaveDto params) {
        this.clockMapper.updateClockEndTimeByEndTime(params);
    }

    @Override
    public SignInDto queryClockByUserId(Integer userId) {
        SignInDto signInDto = this.clockMapper.queryClockByUserId(userId);
        return signInDto;
    }

    @Override
    public void addClock(Integer userId) {
        this.clockMapper.addClock(userId);
    }

    @Override
    public List<ClockRankDto> queryClockRank() {
        List<ClockRankDto> clockRankDtos = this.clockMapper.queryClockRank();
        ClockRankDto clockRankDto = clockRankDtos.get(0);
        clockRankDto.setDiff(0);
        return clockRankDtos;
    }

    @Override
    public ClockRankDto queryClockRankByUserId(Integer userId) {
        ClockRankDto clockRankDto = this.clockMapper.queryClockRankByUserId(userId);
        if(clockRankDto.getSequence()==1)
        {
            clockRankDto.setDiff(0);
        }
        return clockRankDto;
    }
}
